<?php
require_once "jssdk.php";
//JSSDK中的参数是appid和appsecret。 
$jssdk = new JSSDK("wxa8333bbf9962d0e0", "X5WGFMDa00mur1y0T2oLCZiItOIhcFFJGUnl6REWqsE");
$signPackage = $jssdk->GetSignPackage();
//print_r($signPackage);die;
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>企业微信JS-SDK Demo</title>
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<style type="text/css">
html {
    -ms-text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
    -webkit-user-select: none;
    user-select: none;
  }
  body {
    line-height: 1.6;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    background-color: #f1f0f6;
  }
  * {
    margin: 0;
    padding: 0;
  }
  button {
    font-family: inherit;
    font-size: 100%;
    margin: 0;
    *font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  }
  ul,
  ol {
    padding-left: 0;
    list-style-type: none;
  }
  a {
    text-decoration: none;
  }
  .label_box {
    background-color: #ffffff;
  }
  .label_item {
    padding-left: 15px;
  }
  .label_inner {
    padding-top: 10px;
    padding-bottom: 10px;
    min-height: 24px;
    position: relative;
  }
  .label_inner:before {
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    width: 200%;
    height: 1px;
    border-top: 1px solid #ededed;
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0;
    -webkit-transform: scale(0.5);
    transform: scale(0.5);
    top: auto;
    bottom: -2px;
  }
  .lbox_close {
    position: relative;
  }
  .lbox_close:before {
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    width: 200%;
    height: 1px;
    border-top: 1px solid #ededed;
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0;
    -webkit-transform: scale(0.5);
    transform: scale(0.5);
  }
  .lbox_close:after {
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    width: 200%;
    height: 1px;
    border-top: 1px solid #ededed;
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0;
    -webkit-transform: scale(0.5);
    transform: scale(0.5);
    top: auto;
    bottom: -2px;
  }
  .lbox_close .label_item:last-child .label_inner:before {
    display: none;
  }
  .btn {
    display: block;
    margin-left: auto;
    margin-right: auto;
    padding-left: 14px;
    padding-right: 14px;
    font-size: 18px;
    text-align: center;
    text-decoration: none;
    overflow: visible;
    /*.btn_h(@btnHeight);*/
    height: 42px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    color: #ffffff;
    line-height: 42px;
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0);
  }
  .btn.btn_inline {
    display: inline-block;
  }
  .btn_primary {
    background-color: #437DBA;
  }
  .btn_primary:not(.btn_disabled):visited {
    color: #ffffff;
  }
  .btn_primary:not(.btn_disabled):active {
    color: rgba(255, 255, 255, 0.9);
    background-color: #3b78b9;
  }
  button.btn {
    width: 100%;
    border: 0;
    outline: 0;
    -webkit-appearance: none;
  }
  button.btn:focus {
    outline: 0;
  }
  .wxapi_container {
    font-size: 16px;
  }
  h1 {
    font-size: 14px;
    font-weight: 400;
    line-height: 2em;
    padding-left: 15px;
    color: #8d8c92;
  }
  .desc {
    font-size: 14px;
    font-weight: 400;
    line-height: 2em;
    color: #8d8c92;
  }
  .wxapi_index_item a {
    display: block;
    color: #3e3e3e;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  }
  .wxapi_form {
    background-color: #ffffff;
    padding: 0 15px;
    margin-top: 30px;
    padding-bottom: 15px;
  }
  h3 {
    padding-top: 16px;
    margin-top: 25px;
    font-size: 16px;
    font-weight: 400;
    color: #3e3e3e;
    position: relative;
  }
  h3:first-child {
    padding-top: 15px;
  }
  h3:before {
    content: " ";
    position: absolute;
    left: 0;
    top: 0;
    width: 200%;
    height: 1px;
    border-top: 1px solid #ededed;
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0;
    -webkit-transform: scale(0.5);
    transform: scale(0.5);
  }
  .btn {
    margin-bottom: 15px;
  }
</style>
</head>
<body ontouchstart="">
<div class="wxapi_container">
	<div class="wxapi_index_container">
		<ul class="label_box lbox_close wxapi_index_list">
			<li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-location">地理位置接口</a><span id="spandd"></span></li>
		</ul>
	</div>
	<div class="lbox_close wxapi_form">
		
		<h3 id="menu-location">地理位置接口</h3>
		<span class="desc">使用企业微信内置地图查看位置接口</span>
		<button class="btn btn_primary" id="openLocation">openLocation</button>
		<span class="desc">获取地理位置接口</span>
		<button class="btn btn_primary" id="getLocation">getLocation</button>

		<span class="desc">开启持续定位</span>
		<button class="btn btn_primary" id="startAutoLBS">startAutoLBS</button>
		<span class="desc">关闭持续定位</span>
		<button class="btn btn_primary" id="stopAutoLBS">stopAutoLBS</button>
	
	</div>
</div>
</body>
<script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="//cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script>
  
  /*
   * 注意：
   * 所有的JS接口只能在应用配置的安全域名下面使用。   
   *
   */
  wx.config({
      debug: false,
      beta: true,
      appId: '<?php echo $signPackage["appId"];?>',
 timestamp: <?php echo $signPackage["timestamp"];?>,
 nonceStr: '<?php echo $signPackage["nonceStr"];?>',
 signature: '<?php echo $signPackage["signature"];?>',
      jsApiList: [
        'openLocation',
        'getLocation',
      ]
  });
	  wx.ready(function () {
               //alert("aa:"+location.href.split('#')[0])
               // 7.1 位置地图
               document.querySelector('#openLocation').onclick = function () {
                   wx.openLocation({
                       latitude: 23.099994,
                       longitude: 113.324520,
                       name: 'TIT 创意园',
                       address: '广州市海珠区新港中路 397 号',
                       scale: 14,
                       infoUrl: 'http://weixin.qq.com'
                   });
               };
			  // 7.2 查看地理位置
               document.querySelector('#getLocation').onclick = function () {
                       wx.getLocation({                
                           type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
                           success: function (res) {alert(1)
                               var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                               var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                               var speed = res.speed; // 速度，以米/每秒计
                               var accuracy = res.accuracy; // 位置精度
                               alert("latitude"+latitude +" longitude"+longitude);
                           },
                           cancel: function (res) {
                               alert('用户拒绝授权获取地理位置');
                           }
                       });
               };
               document.querySelector('#startAutoLBS').onclick = function () {
                     wx.invoke('startAutoLBS',{
							type: 'wgs84', // wgs84是gps坐标，gcj02是火星坐标
						  },
						  function(res) {
							 if(res.err_msg == "startAutoLBS:ok"){
								alert('已开启');
								localchange();
							 }else {
								alert(res);
							}
						  });
               };
               document.querySelector('#stopAutoLBS').onclick = function () {
                      wx.invoke('stopAutoLBS',{},
					  function(res) {
						 if(res.err_msg == "stopAutoLBS:ok"){
							alert('已关闭');
						 }else {
							alert(res);
						}
					  });
               };
			  function localchange(){
			   wx.onLocationChange( 
				  function(res) {
					if(res.errMsg == "auto:location:report:ok"){
					  var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
					  var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
					  var speed = res.speed; // 速度，以米/每秒计
					  var accuracy = res.accuracy; // 位置精度
					  var lbsIndex = 0;
					    $.post("https://oa.fc62.com/open/demo/addpoint2.php",{latitude:latitude,longitude:longitude,speed:speed,accuracy:accuracy},function(result){
							$("#spandd").text('latitude:'+latitude+'\n longitude:'+longitude);
						});
					}else {
					  //错误处理
					}
				  }
				);
			   }
           });
	  
	  </script>

</html>